package com.naiterui.ehp.bs.emr.vo.health;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.date.DateUtil;
import com.naiterui.ehp.bs.emr.exception.ExceptionCodes;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @Description 预防接种史
 * @Author gongbaoqiang
 * @Date 2020/6/2 2:28 PM
 */
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("预防接种史")
public class VaccinationVO implements Serializable {
    private static final long serialVersionUID = -6536885636991762577L;

    /**
     * 外伤史
     */
    @ApiModelProperty("选项值")
    private String value;

    /**
     * 外伤详情
     */
    @ApiModelProperty("外伤详情")
    private VaccinationDetailVO detail;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class VaccinationDetailVO implements Serializable{

        private static final long serialVersionUID = 1625086589722034071L;
        /**
         * 接种疫苗
         */
        @ApiModelProperty("接种疫苗")
        private String  name;

        /**
         * 最近一次接种日期
         */
        @ApiModelProperty("最近一次接种日期")
        @JsonFormat(pattern = DateUtil.DATE_FORMAT)
        private Date date;

        public void validate() throws BusinessException {
            if(date == null || StringUtils.isBlank(name)){
                throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_VACCINATION);
            }
        }
    }

    public void validate() throws BusinessException{
        if(StringUtils.isBlank(value)){
            throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_VACCINATION);
        }
        if("有".equals(value)){
            detail.validate();
        }
    }
}
